﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using AliyunOpenSearch4Net.Base;

namespace AliyunOpenSearch4Net.Base
{
    abstract class RequestBase
    {
        protected RequestBase(string action)
        {
            Action = action;
        }        

        public string Action { get; private set; }

        protected virtual void RegisterQueryItems(IList<KeyValuePair<string, string>> list)
        {

        }

        protected virtual void RegisterAdditionalItems(IList<KeyValuePair<string, string>> list)
        {

        }

        internal QueryDataSet MakeQueryData(CommonQueryInfo commonQueryInfo)
        {
            var data = new QueryDataSet();
            commonQueryInfo.Register(data.CommonQueryItems);

            if (!string.IsNullOrEmpty(Action))
                data.QueryItems.Add("action", Action);

            RegisterQueryItems(data.QueryItems);
            RegisterAdditionalItems(data.AdditionalItems);
            return data;
        }
    }


    abstract class RequestBase<TResponse> : RequestBase
        where TResponse : Response
    {
        protected RequestBase(string action)
            : base(action)
        {

        }
    }
}
